package com.dsz.controller;

import java.sql.Timestamp;
import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.dsz.po.Order;
import com.dsz.service.OrderService;

/**
 * 订单controller层
 * 
 * @author 吴生伟
 *
 */
@Controller
public class OrderController {
	// 依赖注入
	@Autowired
	private OrderService orderService;

	// 查询所有订单
	@RequestMapping(value = "toorders.action")
	public String toorder(Model model) {
		List<Order> listorder = orderService.findAllOrder();
		model.addAttribute("listorders", listorder);
		return "backadmin/order/order-list";

	}

	// 跳转到添加页面
	@RequestMapping(value = "toaddorder.action")
	public String toaddorder() {
		return "backadmin/order/order-add";
	}

	// 添加订单
	@RequestMapping(value = "addorder.action", method = RequestMethod.POST)
	public String addorder(Order order, Model model) {
		//日期转换待解决
		
		int rows = orderService.addOrder(order);
		if (rows > 0) {
			System.out.println("添加成功");
			return "redirect:toorders.action";
		}
		System.out.println("添加失败");
		model.addAttribute("msg", "添加失败");
		return "toaddorder.action";

	}
	
	//删除订单
	@RequestMapping(value="deleteorder.action")
	@ResponseBody
	public String deleteoeder(Integer code) {
		int rows = orderService.deleteOrder(code);
		if(rows>0) {
			return "OK";
		}else {
			return "FAIL";
		}
		
		
	}
}
